<?php
require_once 'EZend/Controller/WebBaseController.php';

class CategoryController extends WebBaseController {
	
	public function indexAction() {
		$currentCategory = $this->getCmsArticleService()->getCategoryByName($this->getRequest()->getParam('category'));
		if (!$currentCategory) return $this->showNotice('找不到分类');
		
		$secondLevelCategory = $currentCategory['parent_id'] ? $this->getCmsArticleService()->getCategory($currentCategory['parent_id']) : $currentCategory;
		if (!$secondLevelCategory) return $this->showNotice('找不到分类');
		
		$this->view->assign('currentCategory', $currentCategory);
		$this->view->assign('secondLevelCategory', $secondLevelCategory);
		$this->view->assign('subCategories', $this->getCmsArticleService()->listSubCategories($secondLevelCategory['id']));
		
		$this->view->assign('navigates', $this->getCmsArticleService()->listTopCategories());
		
		$this->view->assign('articles', $this->getCmsArticleService()->listInPage(1, 7, $currentCategory['id']));
	}
	
	
	private function getCmsArticleService() {
		require_once 'Models/Cms/Service/CmsServiceFactory.php';
		return CmsServiceFactory::getInstance()->createCmsArticleService();
	}
}